﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.Diagnostics;
using System.Windows.Forms;

namespace Screenshot2Disk
{
    public class SecurityHelper
    {
        public static bool IsAdmin()
        {
            bool isElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
            return isElevated;
        }

        public static void StartElevated(Form mainForm)
        {
            try
            {
                StartElevated(Application.ExecutablePath, Environment.CurrentDirectory, null);
            }
            catch (Exception ex)
            {
                return;
            }

            Application.Exit();
            mainForm.Activate();
        }

        private static void StartElevated(
  string filename, string workingDirectory, string arguments)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.UseShellExecute = true;
            startInfo.Verb = "runas";
            startInfo.WorkingDirectory = workingDirectory;
            startInfo.FileName = filename;
            startInfo.Arguments = arguments;

            Process.Start(startInfo);
            
        }
    }
}
